<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <ul id="mylist">
        <li>aaa</li>
        <li>bbb</li>
    </ul>
    <script>
        // 为什么要自己写
        // 因为js默认不会判断，所以要自己封装一下
        addEventListener('#mylist','click',function(event){
            console.log('click')
        },'li')

        function addEventListener(container,type,callback,selector){
         
          if(typeof container ==="string"){
            ele=document.querySelector(container)
          }else{

          }

          if(selector){
            ele.addEventListener(type,function(e){
                if(e.target.nodeName.toLowerCase()==selector){
                    console.log(e,e.target.nodeName=='LI')
                    callback(e)
                }
                
            })
          }else{
            ele.addEventListener(type,callback)
          }
            
          
        }
    </script>
</body>
</html>